home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / pvm34b3.zip / pvm34b3 / pvm3 / libfpvm / pvmfstartpvmd.m4 < prev    next >
Text File  |  1997-07-22  |  4KB  |  131 lines

  1.  
  2. /* $Id: pvmfstartpvmd.m4,v 1.2 1996/10/04 15:27:41 pvmsrc Exp $ */
  3.  
  4. /*
  5.  *----------------------------------------------------------------------
  6.  * Time-stamp: "1995/11/21 13:31:32 thibaud@kether.cgd.ucar.edu"
  7.  *----------------------------------------------------------------------
  8.  */
  9. /*
  10.  *----------------------------------------------------------------------
  11.  * pvmfstartpvmd.m4
  12.  *
  13.  * Interface to Fortran for pvm_start_pvmd()
  14.  *----------------------------------------------------------------------
  15.  */
  16.  
  17. #include <stdio.h>
  18. #include "pvm3.h"
  19. #include "pvm_consts.h"
  20. #include "pvmalloc.h"
  21.  
  22. void
  23. FUNCTION(pvmfstartpvmd) ARGS(`STRING_ARG(args), block, info')
  24. STRING_ARG_DECL(args);
  25. int *block;
  26. int *info;
  27. {
  28.     char *nargs;            /* args (null terminated) */
  29.     int ac = 0;                /* # of agruments initialize to 0 */
  30.     char **av;                /* argument vector */
  31.     register char *ch;            /* temp char pointer */
  32.     register char *beg;            /* pointer to begining of word */
  33.     register char *end;            /* pointer to end of word */
  34.     register int len;            /* length of word */
  35.     register int i;            /* loop index */
  36.  
  37. #if ( DEBUG )
  38.     /* printout incoming nargs */
  39.     printf( "%d \"%s\"\n", STRING_LEN(args), STRING_PTR(args) );
  40. #endif
  41.     /* Some Fortran compilers allow for strings of zero length */
  42.     if ( STRING_LEN(args) == 0 ) {    /* null args */
  43.     av = (char **)0;        /* make av a null pointer */
  44.     goto pvmd;
  45.     } else {                /* something in args */
  46.     if ( ( nargs = TALLOC( STRING_LEN(args) + 1, char, "nargs" ) )
  47.         == NULL ) {
  48.         pvmlogerror("pvmfstartpvmd() can't get memory\n");
  49.         goto bail;
  50.     }
  51.     /* copy args (ftocptr() could have been used for that) */
  52.     strncpy( nargs, STRING_PTR(args), STRING_LEN(args) );
  53.     nargs[STRING_LEN(args)] = '\0'; /* terminate with null */
  54.     }
  55.     ch = nargs;                /* pointer at the begining of nargs */
  56.     /* assume a max of 32 args (8 should be OK from pvmd3(3PVM)) */
  57.     if ( ( av = TALLOC( 32, char *, "av" ) ) == NULL ) {
  58.     pvmlogerror("pvmfstartpvmd() can't get memory\n");
  59.     PVM_FREE( nargs );        /* avoid memory leeks */
  60.     goto bail;
  61.     }
  62.     /* at this point nargs contain at least 1 char */
  63.     for ( ; ; ) {
  64.     /* move forward until no space nor tab */
  65.     for( ; *ch == ' ' || *ch == '\t'; ch++ );
  66.     beg = ch;            /* that's the begining of a word */
  67.     /* move forward until space, tab or null */
  68.     for( ; *ch != ' ' && *ch != '\t' && *ch != '\0'; ch++ );
  69.     end = ch;            /* that's the end of a word */
  70.     len = end - beg;        /* length of the word */
  71.     /* if nothing else then space, tab or null has been found */
  72.     /* then end of nargs is reached (exit point of loop) */
  73.     if ( len == 0 ) break;
  74.     /* allocate memory for word in agument vector */
  75.     if ( ( av[ac] = TALLOC( len + 1, char, "av[ac]" ) ) == NULL ) {
  76.         pvmlogerror("pvmfstartpvmd() can't get memory\n");
  77.         PVM_FREE( nargs );        /* avoid memory leeks */
  78.         for ( i = 0; i < ac; i++ )
  79.         PVM_FREE( av[i] );
  80.         goto bail;
  81.     }
  82.     strncpy( av[ac], beg, len );    /* copy word to arg vector */
  83.     *( av[ac] + len ) = '\0';    /* null terminate word */
  84.     ac++;                /* increment arg counter */
  85.     }
  86. #if ( DEBUG )
  87.     printf( "ac is %d\n", ac );
  88. #endif
  89.     if ( ac == 0 ) {
  90.     /* no args found */
  91.     PVM_FREE( av );            /* free allocated memory */
  92.     av = (char **)0;        /* make av a NULL pointer */
  93. #if ( DEBUG )
  94.     } else {
  95.     /* printout result */
  96.     for ( i = 0; i < ac; i++ )
  97.         printf( "av[%2d] is \"%s\"\n", i, av[i] );
  98. #endif
  99.     }
  100.     PVM_FREE( nargs );            /* free allocated memory */
  101.  pvmd:
  102.     /* hopefully pvm_start_pvmd is freeing allocated mem for av */
  103.     *info = pvm_start_pvmd( ac, av, *block );
  104.     return;
  105.  bail:
  106.     *info = -1;
  107.     return;
  108. }
  109.  
  110. /*
  111.  *----------------------------------------------------------------------
  112.  * RCS identification
  113.  *----------------------------------------------------------------------
  114.  * $Author: pvmsrc $
  115.  * $Date: 1996/10/04 15:27:41 $
  116.  * $Locker:  $
  117.  * $Revision: 1.2 $
  118.  * $Source: /home/nova/u3/pvmsrc/.CVS/PVM/pvm3.4/libfpvm/pvmfstartpvmd.m4,v $
  119.  * $State: Exp $
  120.  *----------------------------------------------------------------------
  121.  * For GNU Emacs:
  122.  *----------------------------------------------------------------------
  123.  * Local Variables:
  124.  * mode: C
  125.  * abbrev-mode: t
  126.  * comment-column: 40
  127.  * version-control: t
  128.  * End:
  129.  *----------------------------------------------------------------------
  130.  */
  131.